package util

import (
	"math/rand"
)

var lock chan bool
var ri int

func init() {
	lock = make(chan bool, 1)
}

/*
function:轮询所有的调度
author:
date:
in para:
out para:
*/
func Round_robin(path []string) int64 {
	len := len(path)

	lck := <-lock
	i := ri % len
	if i == 0 {
		ri = 0
	}
	ri++
	lock <- lck
	if len != 0 {
		rnd := rand.New(rand.NewSource(int64(i)))
		return int64(rnd.Int())
	}
	return 0
}
